package cuit.cx.groupcomment.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import cuit.cx.groupcomment.dao.UserinfoDAO;
import cuit.cx.groupcomment.model.Userinfo;

public class UserinfoDAOImpl extends SqlMapClientDaoSupport implements UserinfoDAO 
{
	private Logger log = Logger.getLogger(UserinfoDAOImpl.class);

    public UserinfoDAOImpl() {
        super();
    }

    public void insert(Userinfo record) 
    {
    	log.info("insert user");
    	System.out.println("insert user");
        Object object =  getSqlMapClientTemplate().insert("addUserinfo", record);
        System.out.println(object);
    }

    public int updateUserinfo(Userinfo record) 
    {
        int rows = getSqlMapClientTemplate().update("updateUserinfo", record);
        return rows;
    }

    public Userinfo findUserinfoById(Integer id) 
    {
        Userinfo key = new Userinfo();
        key.setId(id);
        Userinfo record = (Userinfo) getSqlMapClientTemplate().queryForObject("getUserinfoById", key);
        return record;
    }

    public int deleteUserinfo(Integer id) {
        Userinfo key = new Userinfo();
        key.setId(id);
        int rows = getSqlMapClientTemplate().delete("delUserinfo", key);
        return rows;
    }

	@SuppressWarnings("unchecked")
	public List<Userinfo> getUserinfos(Userinfo userinfo) {
	return	getSqlMapClientTemplate().queryForList("getUserinfos", userinfo);
		//return null;
	}

	@SuppressWarnings("unchecked")
	public boolean checkUserIsExist(String email)
	{
		List<Integer> list = getSqlMapClientTemplate().queryForList("checkUserIsExist", email);
		if (list != null && list.size() > 1)
		{
			return true;
		}
		return false;
	}
	
	
	public Userinfo findUserinfo(Userinfo userinfo)
	{
		List<Userinfo> list = getUserinfos(userinfo);
		if (list != null && list.size() == 1)
		{
			return list.get(0);
		}
		return null;
	}
	
	

}